/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef PAGCOMPOSITION_H
#define PAGCOMPOSITION_H
#include <ace/xcomponent/native_interface_xcomponent.h>
#include "napi/native_api.h"
#include <bits/alltypes.h>
#include <string>
#include "pag/pag.h"
#include "napi/PagCompositionProxy.h"

namespace NativeXComponentSample {
class PAGComposition {
public:
    PAGComposition(napi_env pEnv, std::string &id);
    PAGComposition(napi_env pEnv, napi_ref pRef);
    ~PAGComposition();
    static PAGComposition *getInstance(napi_env pEnv, std::string &id);
    static napi_value PAGCompositionInit(napi_env env, napi_callback_info info);
    static napi_value AddLayer(napi_env env, napi_callback_info info);
    static napi_value GetLayerAt(napi_env env, napi_callback_info info);
    static napi_value RemoveLayer(napi_env env, napi_callback_info info);
    static napi_value RemoveAllLayers(napi_env env, napi_callback_info info);
    static napi_value JsPlayerConstructor(napi_env env, napi_callback_info info);
    static napi_value NumChildren(napi_env env, napi_callback_info info);
    static napi_value AddLayerAt(napi_env env, napi_callback_info info);
    static napi_value RemoveLayerAt(napi_env env, napi_callback_info info);
    static PAGComposition* GetNapiComposition(napi_env env, napi_callback_info info);
    static void Destructor(napi_env env, void *nativeObject, void *finalize); // 释放资源的函数(类似类的析构函数)
    static napi_ref sJSPlayerConstructor_; // 生命周期变量
private:
    napi_env mEnv = nullptr; // 记录环境变量
    napi_ref mRef = nullptr; // 记录生命周期变量
    static std::string _msg; // 设置和获取数据的变量
    static std::unordered_map<std::string, PAGComposition *> pagCompositionNapiMap_;
    PagCompositionProxy *pagCompositionProxy_;
};
}
#endif